/*
@Time : 2020/6/20 16:35
@Author : yaodongpo
@File : BaseController
@Software: GoLand
*/
package controllers

import (
	"encoding/json"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
)

type BaseController struct {
	beego.Controller
}

//ajax返回 app用status 0失败|1成功
func (self *BaseController) AjaxInfo(status int, msg interface{}, data ...interface{}) {
	out := make(map[string]interface{})
	if status == 0 {
		out["info"] = msg
		if data != nil {
			out["data"] = data
		} else {
			out["data"] = nil
		}
	} else {
		out["info"] = nil
		out["data"] = msg
	}
	out["status"] = status
	self.Data["json"] = out

	dataJson, _ := json.Marshal(out)
	dataString := string(dataJson)
	logs.Info(self.Ctx.Request.RequestURI + "===" + dataString)

	self.ServeJSON()
	self.StopRun()
}

